{**************************************************************************************************}
{ The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); }
{ you may not use this file except in compliance with the License. You may obtain a copy of the    }
{ License at http://www.mozilla.org/MPL/                                                           }
{                                                                                                  }
{ Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF   }
{ ANY KIND, either express or implied. See the License for the specific language governing rights  }
{ and limitations under the License.                                                               }
{                                                                                                  }
{ The Original Code is BaseGisConsole.pas                                                          }
{                                                                                                  }
{ The Initial Developer of the Original Code is Fabrizio Vita (fabrizio.vita@itacasoft.com)        }
{**************************************************************************************************}
unit BaseGisConsole;

interface

uses Classes, SysUtils, GisViewerWnd, forms, ActiveX;


type
  TBaseGISConsole = Class(TObject)
  private
    _progress: single;
    frm: TForm;
    destructor Destroy; override;
  protected
    GIS : TGIS_ViewerWnd;
    procedure GISOnBusy(const _sender: TObject; const _pos, _end: Integer; var _abort: Boolean);
    procedure CheckParameters; virtual; abstract;
  public
    procedure Run; virtual;
    constructor Create;
  end;


implementation

uses Math;


constructor TBaseGISConsole.create;
begin
   frm := TForm.Create(Application);
   frm.Visible := false;
   GIS := TGIS_ViewerWnd.Create(frm);
   GIS.Parent := frm;
   GIS.OnBusy := GISOnBusy;
end;



destructor TBaseGISConsole.Destroy;
begin
   GIS.Close;
   frm.Free;
   inherited;
end;


procedure TBaseGISConsole.GISOnBusy(const _sender: TObject; const _pos, _end: Integer; var _abort: Boolean);
var
   perc: single;
begin
   if (_end = -1) then exit;
   if (_pos = -1) then exit;

   perc := (_pos/_end);
   if floor(perc*100) > floor(_progress*100) then
   begin
     _progress := perc;
     WriteLn(' progress ' +  Inttostr(trunc(perc*100)) + '%');
   end;
end;

procedure TBaseGISConsole.Run;
begin
   _progress := 0;
   CheckParameters;
end;


initialization
   CoInitialize(nil); // <-- manually call CoInitialize()


finalization
   CoUnInitialize; // <-- free memory

end.
